//
//  NetworkTools.swift
//  DouYuZB
//
//  Created by DSDL on 2016/10/31.
//  Copyright © 2016年 鼎商动力. All rights reserved.
//

import UIKit
import Alamofire
enum MethodType {
    case get
    case post
}
class NetworkTools {
    
    class func requestData(_ type: MethodType, URLString: String, parameters: [String: Any]? = nil, finishedCallback:@escaping (_ result: Any) -> ()) {
        //1.获取类型
        let method = type == .get ? HTTPMethod.get : HTTPMethod.post
        //2.发送网络请求
        Alamofire.request(URLString, method: method, parameters: parameters).responseJSON { (response) in
            //3.获取数据
            guard let result = response.result.value else{
                print(response.result.error!)
                return
            }
            
            //4.返回数据
            finishedCallback(result)
        }
    }
    
}
